package com.lm.paymentadmin.service;

import com.lm.paymentadmin.domain.ToEmail;
import org.springframework.mail.MailException;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author liu2dog
 */
@Service
public class EmailService {

    @Resource
    private JavaMailSenderImpl javaMailSender;

    public String sendEmail(ToEmail toEmail){
        //创建简单邮件消息
        SimpleMailMessage message = new SimpleMailMessage();
        //谁发的
        message.setFrom("13961490361@163.com");
        //谁要接收
        message.setTo(toEmail.getTos());
        //邮件标题
        message.setSubject(toEmail.getSubject());
        //邮件内容
        message.setText(toEmail.getContent());
        try {
            javaMailSender.send(message);
            return toEmail.getTos()[0];
        } catch (MailException e) {
            return e.getMessage();
        }
    }
}
